package com.yxplearn.mybatisplus;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Log4j2
@EnableScheduling
@EnableJpaRepositories
@SpringBootApplication
@MapperScan("com.yxplearn.mybatisplus.mapper")
public class SpringBootApp {

	private static ApplicationContext applicationContext;

	private static Logger logger = LogManager.getLogger(SpringBootApp.class);

	public static void main(String[] args) {
		System.setProperty("appName", "mybatisplus");
		System.setProperty("logInfo", "][][");
		System.setProperty("logInfo", getLogInfo());
		applicationContext = SpringApplication.run(SpringBootApp.class, args);
		Runtime.getRuntime().addShutdownHook(new shutdownHookT());
		logger.info("起服成功111");
		log.info("起服成功222");
//		ApplicationContext context = new ClassPathXmlApplicationContext("spring-context-mybatis.xml");

	}

	public static String getLogInfo(){
		return "xxxppp";
	}

	static class shutdownHookT extends Thread{
		@Override
		public void run() {
			Map<String, BaseMapper> beansOfType = applicationContext.getBeansOfType(BaseMapper.class);
			beansOfType.values().stream().forEach(System.out::println);
			logger.info("开始停服完后");
		}
	}
}
